package com.xyz.ai.tools;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xyz.ai.entity.Tutorials;
import com.xyz.dao.TutorialsMapper;
import com.xyz.ai.service.TutorialsService;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class TutorialsTools {

    @Autowired
    private TutorialsService tutorialsService;

    @Autowired
    private TutorialsMapper tutorialsMapper;

    @Tool(name = "查询所有的课程信息" ,value = "当用户询问有哪些课程时调用，或者当用户询问有没有推荐的课程时调用该方法，返回给用户课程的基本信息，并根据课程名字和用户需求给出推荐课程")
    public String getAllTutorials() {
        List<Tutorials> tutorials = tutorialsService.list();
        if (tutorials.isEmpty()) {
            return "没有查询到课程";
        }
        return tutorials.toString();
    }

    @Tool(name = "根据名称查询课程信息" ,value = "当用户询问某个课程时调用，返回给用户课程信息并作出学习指引")
    public String getTutorialsByName(@P("课程名称") String name) {
        List<Tutorials> tutorials = tutorialsMapper.selectList(new QueryWrapper<Tutorials>()
                .like("title", name));
        if (tutorials.isEmpty()) {
            return "没有查询到课程";
        }
        return tutorials.toString();
    }
}